#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
struct node
{
	ll g;
	ll t;
	int num;
};
int main()
{
	IOS;
	int tt;
	cin>>tt;
	while(tt--)
	{
		ll n,m,t;
		cin>>n>>m>>t;
		vector<ll> a[n+5];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				ll num;
				cin>>num;
				a[i].push_back(num);
			}
		}
		for(int i=0;i<n;i++)
		{
			sort(a[i].begin(),a[i].end());
		}
		ll g1=0,h1=0;
		int p=1;
		for(int i=0;i<n;i++)
		{
			ll sum=0;
			int j=0;
			ll h=0;
			while(sum<=t && j<a[i].size())
			{
				sum=sum+a[i][j];
				if(sum>t) break;
				h+=sum;
				j++;
			}
//			j=min(j,0);
			if(i==0)
			{
				g1=j;
				h1=h;
			}
			else
			{
				if(j>g1) p++;
				else if(j==g1 && h<h1) p++;
			}
//			cout<<j<<' '<<h<<endl;
		}
		cout<<p<<endl;
		
	} 

	return 0;
}

